package com.katze.boot.system.domain;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.katze.common.tree.Node;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

import java.io.Serial;

@Data
@EqualsAndHashCode(callSuper = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class MenuNode extends Node {

    @Serial
    private static final long serialVersionUID = -8075230310222374411L;

    private String menuId;

    private String parentId;

    private String title;

    private String type = null;

    private String perms;

    private String component;

    private String code;

    private String params;

    private Double orderNum;

    public MenuNode(){}
    
    public MenuNode(Menu item){
        this(item.getMenuId(), item.getParentId(), item.getTitle());
        setTitle(item.getTitle());
        setIcon(item.getIcon());
        setComponent(item.getComponent());
        setCreateTime(item.getCreateTime());
        setModifyTime(item.getModifyTime());
        setPath(item.getPath());
        setOrderNum(item.getOrderNum());
        setPerms(item.getPerms());
        setType(item.getType());
        setCode(item.getCode());
        setParams(item.getParams());
    }

    public MenuNode(String id, String pid, String name){
        super(id, StringUtils.isBlank(pid)? "0":pid, name);
        this.menuId = id;
        this.parentId = pid;
    }

    public void setMenuId(String menuId) {
        this.menuId = menuId;
        setId(menuId);
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
        setPid(StringUtils.isBlank(parentId)? "0":parentId);
    }

    @Override
    public Integer getOrder() {
        return this.orderNum == null? 0:this.orderNum.intValue();
    }
}
